<?php
declare (strict_types = 1);

namespace app\common\model;

use think\Request;
use think\Model;
use think\model\concern\SoftDelete;
use app\common\model\AdminZavote as M;
use think\facade\Cache;
use think\facade\Db;
class AdminZccandidate extends Model
{
    use SoftDelete;
     protected $deleteTime = false;
    // 获取列表
    public static function getList($biaoid)
    {
        $where = [];
        $limit = input('get.limit');
               //按名称查找
               if ($name = input("name")) {
                   $where[] = ["name", "like", "%" . $name . "%"];
               }
               //按编号查找
               if ($bianhao = input("bianhao")) {
                   $where[] = ["bianhao", "like", "%" . $bianhao . "%"];
               }
               //按组别查找
               if ($group = input("group")) {
                    $where[] = ["group", "like", "%" . $group . "%"];
                }
               //按编号查找
               if ($biaoid) {
                    $where[] = ["biaoid", "like",  $biaoid ];
                }
        $list = self::order('id','desc')->where($where)->paginate($limit);
        return ['code'=>0,'data'=>$list->items(),'extend'=>['count' => $list->total(), 'limit' => $limit]];
    }

    // 候选增加点击量
    public static function hxcat($zid)
    {
        $res = self::find($zid);
        $rand=rand(1,1);
        $data['cat']=$res['cat']+$rand;
        self::where('id', $zid)->update($data);
        return ['code'=>200,'message'=>'成功'];
    }

    // 前台获取候选信息一
    public static function gettpoptionybypid($pid)
    {
        $arrid = Cache::get('tpgettpoptionybypid:'.$pid);
        if($arrid==""){
            $res = M::find($pid);
            if($res['moban'] == 0){
                $where = [];
                $where[] = ["biaoid", "like",  $pid ];
                //$list = self::order('id','desc')->field('id,name,bianhao')->where($where)->where('shenhe',0)->select();
                if($res['pxsx'] == 0){
                    $list = self::order('bianhao','asc')->field('id,name,bianhao')->where($where)->where('shenhe',0)->select();
                } else {
                    $list = self::order('bianhao','desc')->field('id,name,bianhao')->where($where)->where('shenhe',0)->select();
                }
                foreach($list as $key=>$value){
                    $value['checked']=false;
                    $value['disabled']=false;
                }
                Cache::set('tpgettpoptionybypid:'.$pid,$list,310);
                $dqurl =  THTPADMIN;
                $token = request()->buildToken('__token__', 'sha1');
                return ['code'=>200,'message'=>'成功','data'=>$list,'dqurl'=>$dqurl,'token'=>$token];
            }
        } else {
            $list = $arrid;
            $dqurl =  THTPADMIN;
            $token = request()->buildToken('__token__', 'sha1');
            return ['code'=>200,'message'=>'成功','data'=>$list,'dqurl'=>$dqurl,'token'=>$token];
        }
    }

    // 前台获取候选信息一详情
    public static function gettpoptionycontentbypid($pid)
    {
        $page = input('get.page');
        $arrid = Cache::get('tpgettpoptionycontentbypid:'.$pid.$page);
        if($arrid==""){
            $res = M::find($pid);
            if($res['moban'] == 0){
                $where = [];
                $limit = input('get.limit');
                $where[] = ["biaoid", "like",  $pid ];
                //$list = self::order('id','desc')->field('id,name,bianhao,outurl,content,image,numpiao,cat')->where($where)->where('shenhe',0)->paginate($limit);
                if($res['pxsx'] == 0){
                    $list = self::order('bianhao','asc')->field('id,name,bianhao,outurl,content,image,numpiao,cat')->where($where)->where('shenhe',0)->paginate($limit);
                } else {
                    $list = self::order('bianhao','desc')->field('id,name,bianhao,outurl,content,image,numpiao,cat')->where($where)->where('shenhe',0)->paginate($limit);
                }
                Cache::set('tpgettpoptionycontentbypid:'.$pid.$page,$list,310);
                $dqurl =  THTPADMIN;
                $token = request()->buildToken('__token__', 'sha1');
                return ['code'=>200,'message'=>'成功','data'=>$list,'dqurl'=>$dqurl,'token'=>$token, 'limit' => $limit, 'page' => $page];
            }
        } else {
            $limit = input('get.limit');
            $list = $arrid;
            $dqurl =  THTPADMIN;
            $token = request()->buildToken('__token__', 'sha1');
            return ['code'=>200,'message'=>'成功','data'=>$list,'dqurl'=>$dqurl,'token'=>$token, 'limit' => $limit, 'page' => $page];
        }
    }

    // 前台获取候选信息二详情
    public static function gettpoptionebypid($pid)
    {
        $res = M::find($pid);
        // if($res['moban'] == 1){
            if($res['fenzu'] == 0){
                $page = input('get.page');
                $arrid = Cache::get('tpgettpoptionebypid:'.'wufenzu'.$pid.$page);
                if($arrid==""){
                    $where = [];
                    $limit = input('get.limit');
                    $where[] = ["biaoid", "like",  $pid ];
                    //$list = self::order('id','desc')->where($where)->where('shenhe',0)->paginate($limit);
                    if($res['pxsx'] == 0){
                        $list = self::order('bianhao','asc')->where($where)->where('shenhe',0)->paginate($limit);
                    } else {
                        $list = self::order('bianhao','desc')->where($where)->where('shenhe',0)->paginate($limit);
                    }
                    foreach($list as $key=>$value){
                        $value['checked']=false;
                        $value['disabled']=false;
                    }
                    Cache::set('tpgettpoptionebypid:'.'wufenzu'.$pid.$page,$list,310);
                    $dqurl =  THTPADMIN;
                    $token = request()->buildToken('__token__', 'sha1');
                    $count = $list->total();
                    $count_page = $count/$limit;
                    return ['code'=>200,'message'=>'成功','data'=>array("zid"=>"1","title"=>"分组1","test_type"=>"0","zlist"=>$list->items()),'dqurl'=>$dqurl,'token'=>$token,'extend'=>['count' => $count, 'limit' => $limit,'count_page' => ceil($count_page)]];
                } else {
                    $limit = input('get.limit');
                    $dqurl =  THTPADMIN;
                    $token = request()->buildToken('__token__', 'sha1');
                    $count = $arrid->total();
                    $count_page = $count/$limit;
                    return ['code'=>200,'message'=>'成功','data'=>array("zid"=>"1","title"=>"分组1","test_type"=>"0","zlist"=>$arrid->items()),'dqurl'=>$dqurl,'token'=>$token,'extend'=>['count' => $count, 'limit' => $limit,'count_page' => ceil($count_page)]];
                }
            }elseif($res['fenzu'] == 1){
                $page = input('get.page');
                $arrid = Cache::get('tpgettpoptionebypid:'.'youfenzu'.$pid.$page);
                if($arrid==""){
                    $where = [];
                    $limit = input('get.limit');
                    $where[] = ["biaoid", "like",  $pid ];
                    
                    $grouparr=explode('/',$res['fenzuname']);
                    $grouparr=array_filter($grouparr);

                    $list = array();
                    $array = array();
                    for($i=0;$i < count($grouparr);$i++){
                        //$list[$i] = self::order('id','desc')->where($where)->where('group',$grouparr[$i])->where('shenhe',0)->paginate($limit);
                        if($res['pxsx'] == 0){
                            $list[$i] = self::order('bianhao','asc')->where($where)->where('group',$grouparr[$i])->where('shenhe',0)->paginate($limit);
                        } else {
                            $list[$i] = self::order('bianhao','desc')->where($where)->where('group',$grouparr[$i])->where('shenhe',0)->paginate($limit);
                        }
                        foreach($list[$i] as $key=>$value){
                            $value['checked']=false;
                            $value['disabled']=false;
                        }
                        $zong = $list[$i]->total();
                        $count_page = $zong/$limit;
                        $array[$i] = array("zid"=>$i,"title"=>$grouparr[$i],"test_type"=>$i,'count_page' => ceil($count_page),"zlist"=>$list[$i]->items());
                    }
                    Cache::set('tpgettpoptionebypid:'.'youfenzu'.$pid.$page,$array,310);
                    $dqurl =  THTPADMIN;
                    $token = request()->buildToken('__token__', 'sha1');
                    return ['code'=>200,'message'=>'成功','data'=>$array,'dqurl'=>$dqurl,'token'=>$token,'extend'=>['limit' => $limit]];
                } else {
                    $limit = input('get.limit');
                    $dqurl =  THTPADMIN;
                    $token = request()->buildToken('__token__', 'sha1');
                    return ['code'=>200,'message'=>'成功','data'=>$arrid,'dqurl'=>$dqurl,'token'=>$token,'extend'=>['limit' => $limit]];
                }
            }
        // }
    }

    // 前台获取候选信息二详情加
    public static function gettpoptionebypidjia($pid,$group)
    {
        $res = M::find($pid);
        if($res['moban'] == 1){
            if($res['fenzu'] == 0){
                $page = input('get.page');
                $arrid = Cache::get('tpgettpoptionebypidjia:'.'wufenzu'.$pid.$page);
                if($arrid==""){
                    $where = [];
                    $limit = input('get.limit');
                    $where[] = ["biaoid", "like",  $pid ];
                    //$list = self::order('id','desc')->where($where)->where('shenhe',0)->paginate($limit);
                    if($res['pxsx'] == 0){
                        $list = self::order('bianhao','asc')->where($where)->where('shenhe',0)->paginate($limit);
                    } else {
                        $list = self::order('bianhao','desc')->where($where)->where('shenhe',0)->paginate($limit);
                    }
                    Cache::set('tpgettpoptionebypidjia:'.'wufenzu'.$pid.$page,$list,310);
                    $dqurl =  THTPADMIN;
                    $token = request()->buildToken('__token__', 'sha1');
                    return ['code'=>200,'message'=>'成功','data'=>array("zid"=>"1","title"=>"分组1","test_type"=>"1","zlist"=>$list->items()),'dqurl'=>$dqurl,'token'=>$token,'extend'=>['count' => $list->total(), 'limit' => $limit]];
                } else {
                    $limit = input('get.limit');
                    $dqurl =  THTPADMIN;
                    $token = request()->buildToken('__token__', 'sha1');
                    return ['code'=>200,'message'=>'成功','data'=>array("zid"=>"1","title"=>"分组1","test_type"=>"1","zlist"=>$arrid->items()),'dqurl'=>$dqurl,'token'=>$token,'extend'=>['count' => $arrid->total(), 'limit' => $limit]];
                }
            }elseif($res['fenzu'] == 1){
                if($group){
                    $page = input('get.page');
                    $arrid = Cache::get('tpgettpoptionebypidjia:'.'youfenzu'.$group.$pid.$page);
                    if($arrid==""){
                        $where = [];
                        $limit = input('get.limit');
                        $where[] = ["biaoid", "like",  $pid ];
                        
                        $grouparr=explode('/',$res['fenzuname']);
                        $grouparr=array_filter($grouparr);

                        $list = array();
                        $array = array();
                        
                        //$list = self::order('id','desc')->where($where)->where('group',$group)->where('shenhe',0)->paginate($limit);
                        if($res['pxsx'] == 0){
                            $list = self::order('bianhao','asc')->where($where)->where('group',$group)->where('shenhe',0)->paginate($limit);
                        } else {
                            $list = self::order('bianhao','desc')->where($where)->where('group',$group)->where('shenhe',0)->paginate($limit);
                        }
                        $zong = $list->total();
                        $count_page = $zong/$limit;
                        $array = array("zid"=>0,"title"=>$group,"test_type"=>0,'count_page' => ceil($count_page),"zlist"=>$list->items());

                        Cache::set('tpgettpoptionebypidjia:'.'youfenzu'.$group.$pid.$page,$array,310);
                        $dqurl =  THTPADMIN;
                        $token = request()->buildToken('__token__', 'sha1');
                        return ['code'=>200,'message'=>'成功','data'=>$array,'dqurl'=>$dqurl,'token'=>$token,'extend'=>['limit' => $limit, 'group' => $group]];
                    } else {
                        $limit = input('get.limit');
                        $dqurl =  THTPADMIN;
                        $token = request()->buildToken('__token__', 'sha1');
                        return ['code'=>200,'message'=>'成功','data'=>$arrid,'dqurl'=>$dqurl,'token'=>$token,'extend'=>['limit' => $limit, 'group' => $group]];
                    }
                }else{
                    $page = input('get.page');
                    $arrid = Cache::get('tpgettpoptionebypidjia:'.'youfenzu'.$pid.$page);
                    if($arrid==""){
                        $where = [];
                        $limit = input('get.limit');
                        $where[] = ["biaoid", "like",  $pid ];
                        
                        $grouparr=explode('/',$res['fenzuname']);
                        $grouparr=array_filter($grouparr);

                        $list = array();
                        $array = array();
                        
                        //$list = self::order('id','desc')->where($where)->where('group',$grouparr[0])->where('shenhe',0)->paginate($limit);
                        if($res['pxsx'] == 0){
                            $list = self::order('bianhao','asc')->where($where)->where('group',$grouparr[0])->where('shenhe',0)->paginate($limit);
                        } else {
                            $list = self::order('bianhao','desc')->where($where)->where('group',$grouparr[0])->where('shenhe',0)->paginate($limit);
                        }
                        $zong = $list->total();
                        $count_page = $zong/$limit;
                        $array = array("zid"=>0,"title"=>$grouparr[0],"test_type"=>0,'count_page' => ceil($count_page),"zlist"=>$list->items());

                        Cache::set('tpgettpoptionebypidjia:'.'youfenzu'.$pid.$page,$array,310);
                        $dqurl =  THTPADMIN;
                        $token = request()->buildToken('__token__', 'sha1');
                        return ['code'=>200,'message'=>'成功','data'=>$array,'dqurl'=>$dqurl,'token'=>$token,'extend'=>['limit' => $limit, 'group' => $grouparr[0]]];
                    } else {
                        $limit = input('get.limit');
                        $grouparr=explode('/',$res['fenzuname']);
                        $grouparr=array_filter($grouparr);
                        $dqurl =  THTPADMIN;
                        $token = request()->buildToken('__token__', 'sha1');
                        return ['code'=>200,'message'=>'成功','data'=>$arrid,'dqurl'=>$dqurl,'token'=>$token,'extend'=>['limit' => $limit, 'group' => $grouparr[0]]];
                    }
                }
            }
        }
    }

    // 前台获取候选信息二详情搜
    public static function gettpoptionesoubypid($pid,$sou)
    {
        $res = M::find($pid);
        // if($res['moban'] == 1){
            if($res['fenzu'] == 0){
                $page = input('get.page');
                $arrid = Cache::get('tpgettpoptionesoubypid:'.'wufenzu'.$pid.$page);
                if($arrid==""){
                    $where = [];
                    $limit = input('get.limit');
                    $where[] = ["biaoid", "like",  $pid ];
                    //$where[] = ["name|bianhao", "like",  "%".$sou."%" ];
                    if(is_numeric($sou)){
                        $where[] = ["bianhao", "like",  $sou ];
                    } else {
                        $where[] = ["name", "like",  "%".$sou."%" ];
                    }
    
                    //$list = self::order('id','desc')->where($where)->where('shenhe',0)->paginate($limit);
                    if($res['pxsx'] == 0){
                        $list = self::order('bianhao','asc')->where($where)->where('shenhe',0)->paginate($limit);
                    } else {
                        $list = self::order('bianhao','desc')->where($where)->where('shenhe',0)->paginate($limit);
                    }
                    Cache::set('tpgettpoptionesoubypid:'.'wufenzu'.$pid.$page,$list,310);
                    $dqurl =  THTPADMIN;
                    $token = request()->buildToken('__token__', 'sha1');
                    return ['code'=>200,'message'=>'成功','data'=>array("zid"=>"1","title"=>"分组1","test_type"=>"1","zlist"=>$list->items()),'dqurl'=>$dqurl,'token'=>$token,'extend'=>['count' => $list->total(), 'limit' => $limit]];
                } else {
                    $limit = input('get.limit');
                    $dqurl =  THTPADMIN;
                    $token = request()->buildToken('__token__', 'sha1');
                    return ['code'=>200,'message'=>'成功','data'=>array("zid"=>"1","title"=>"分组1","test_type"=>"1","zlist"=>$arrid->items()),'dqurl'=>$dqurl,'token'=>$token,'extend'=>['count' => $arrid->total(), 'limit' => $limit]];
                }
            }elseif($res['fenzu'] == 1){
                $page = input('get.page');
                $arrid = Cache::get('tpgettpoptionesoubypid:'.'youfenzu'.$pid.$page);
                if($arrid==""){
                    $where = [];
                    $limit = input('get.limit');
                    $where[] = ["biaoid", "like",  $pid ];
                    //$where[] = ["name|bianhao", "like",  "%".$sou."%" ];
                    if(is_numeric($sou)){
                        $where[] = ["bianhao", "like",  $sou ];
                    } else {
                        $where[] = ["name", "like",  "%".$sou."%" ];
                    }
    
                    //$list = self::order('id','desc')->where($where)->where('shenhe',0)->paginate($limit);
                    if($res['pxsx'] == 0){
                        $list = self::order('bianhao','asc')->where($where)->where('shenhe',0)->paginate($limit);
                    } else {
                        $list = self::order('bianhao','desc')->where($where)->where('shenhe',0)->paginate($limit);
                    }
                    Cache::set('tpgettpoptionesoubypid:'.'youfenzu'.$pid.$page,$list,310);
                    $dqurl =  THTPADMIN;
                    $token = request()->buildToken('__token__', 'sha1');
                    $zong = $list->total();
                    $count_page = $zong/$limit;
                    return ['code'=>200,'message'=>'成功','data'=>array("zid"=>"1","title"=>"无","test_type"=>"1",'count_page' => ceil($count_page),"zlist"=>$list->items()),'dqurl'=>$dqurl,'token'=>$token,'extend'=>['count' => $list->total(), 'limit' => $limit]];
                } else {
                    $limit = input('get.limit');
                    $dqurl =  THTPADMIN;
                    $token = request()->buildToken('__token__', 'sha1');
                    $zong = $arrid->total();
                    $count_page = $zong/$limit;
                    return ['code'=>200,'message'=>'成功','data'=>array("zid"=>"1","title"=>"无","test_type"=>"1",'count_page' => ceil($count_page),"zlist"=>$arrid->items()),'dqurl'=>$dqurl,'token'=>$token,'extend'=>['count' => $arrid->total(), 'limit' => $limit]];
                }
            }
        // }
    }

    // 前台获取搜
    public static function gettpsoubypid($pid)
    {
        $res = M::find($pid);
        $arrid = Cache::get('tpgettpsoubypid:'.$pid);
        if($arrid==""){
            $where = [];
            $where[] = ["biaoid", "like",  $pid ];
            if($res['pxsx'] == 0){
                $list = self::order('bianhao','asc')->where($where)->where('shenhe',0)->field(array('name'=>'text'))->select();
            } else {
                $list = self::order('bianhao','desc')->where($where)->where('shenhe',0)->field(array('name'=>'text'))->select();
            }
            foreach($list as $key=>$value){
                $value['value']=$key+1;
            }
            Cache::set('tpgettpsoubypid:'.$pid,$list,310);
            $dqurl =  THTPADMIN;
            $token = request()->buildToken('__token__', 'sha1');
            return ['code'=>200,'message'=>'成功','data'=>array("zlist"=>$list),'dqurl'=>$dqurl,'token'=>$token];
        } else {
            $dqurl =  THTPADMIN;
            $token = request()->buildToken('__token__', 'sha1');
            return ['code'=>200,'message'=>'成功','data'=>array("zlist"=>$arrid),'dqurl'=>$dqurl,'token'=>$token];
        }
    }

    // 前台获取候选信息详情
    public static function gettpoptionbypid($xiangid)
    {
        $arrid = Cache::get('tpgettpoptionbypid:'.$xiangid);
        if($arrid==""){
            $list = self::where('id',$xiangid)->where('shenhe',0)->find();
            Cache::set('tpgettpoptionbypid:'.$xiangid,$list,310);
        } else {
            $list = $arrid;
        }
        if($list){
            $shenhe = 0;
            $arrider = Cache::get('tpgettpoptionbypid:'.$xiangid.'er');
            if($arrider==""){
                $res = M::find($list['biaoid']);
                Cache::set('tpgettpoptionbypid:'.$xiangid.'er',$res,310);
            } else {
                $res = $arrider;
            }
            if($res['danxuan'] == 0){
                $danxuan = 0;
            } else {
                $danxuan = 1;
            }
        } else {
            $shenhe = 1;
            $danxuan = 1;
        }
        $dqurl =  THTPADMIN;
        $token = request()->buildToken('__token__', 'sha1');
        return ['code'=>200,'message'=>'成功','data'=>$list,'shenhe'=>$shenhe,'danxuan'=>$danxuan,'dqurl'=>$dqurl,'token'=>$token];
    }

    // 前台获取候选信息排行
    public static function gettpoptionrankingbypid($pid,$group)
    {
        $res = M::find($pid);
        if($res['fenzu'] == 0){
            $page = input('get.page');
            if($page==1){
                $page=0;
            }else{
                $page=$page - 1;
            }
            $arrid = Cache::get('tpgettpoptionrankingbypid:'.'wufenzu'.$pid.$page);
            if($arrid==""){
                $where = [];
                $limit = input('get.limit');
                $where[] = ["biaoid", "like",  $pid ];
                $where[] = ["shenhe", "like",  0 ];
                $diyi = self::order('numpiao','desc')->field('id,name,image,outurl,numpiao')->where($where)->limit(0,1)->select();
                $dier = self::order('numpiao','desc')->field('id,name,image,outurl,numpiao')->where($where)->limit(1,1)->select();
                $disan = self::order('numpiao','desc')->field('id,name,image,outurl,numpiao')->where($where)->limit(2,1)->select();
                Cache::set('tpgettpoptionrankingbypid:'.'wufenzu'.$pid.'yi',$diyi,310);
                Cache::set('tpgettpoptionrankingbypid:'.'wufenzu'.$pid.'er',$dier,310);
                Cache::set('tpgettpoptionrankingbypid:'.'wufenzu'.$pid.'san',$disan,310);
                $start=$page * $limit;
                if(isset($diyi[0]['id'])){
                    $where1[] = ["id", "<>",  $diyi[0]['id'] ];
                }
                if(isset($dier[0]['id'])){
                    $where1[] = ["id", "<>",  $dier[0]['id'] ];
                }
                if(isset($disan[0]['id'])){
                    $where1[] = ["id", "<>",  $disan[0]['id'] ];
                }
                if(isset($diyi[0]['id']) && isset($dier[0]['id']) && isset($disan[0]['id'])){
    
                }else{
                    $where1[] = ["id", "<>",  0 ];
                }
                $list = self::order('numpiao','desc')->field('id,name,image,outurl,numpiao')->where($where)->where($where1)->limit(intval($start),intval($limit))->select();
                Cache::set('tpgettpoptionrankingbypid:'.'wufenzu'.$pid.$page,$list,310);
                $listcount = self::order('numpiao','desc')->field('id,name,image,outurl,numpiao')->where($where)->where($where1)->select();
                Cache::set('tpgettpoptionrankingbypid:'.'wufenzu'.$pid.'zong',$listcount,310);
                $zong = count($listcount);
                $count_page = $zong/$limit;
                $fenzuname = explode('/',$res['fenzuname']);
                $fenzuname = array_filter($fenzuname);
                $dqurl =  THTPADMIN;
                $token = request()->buildToken('__token__', 'sha1');
                return ['code'=>200,'message'=>'成功','data'=>array("diyi"=>$diyi,"dier"=>$dier,"disan"=>$disan,"list"=>$list,'count_page' => ceil($count_page),'fenzuname' => $fenzuname,'fenzunamecount' => count($fenzuname)),'dqurl'=>$dqurl,'token'=>$token, 'limit' => $limit];
            }else{
                $limit = input('get.limit');
                $diyi = Cache::get('tpgettpoptionrankingbypid:'.'wufenzu'.$pid.'yi');
                $dier = Cache::get('tpgettpoptionrankingbypid:'.'wufenzu'.$pid.'er');
                $disan = Cache::get('tpgettpoptionrankingbypid:'.'wufenzu'.$pid.'san');
                
                $list = Cache::get('tpgettpoptionrankingbypid:'.'wufenzu'.$pid.$page);
                $listcount = Cache::get('tpgettpoptionrankingbypid:'.'wufenzu'.$pid.'zong');
                $zong = count($listcount);
                $count_page = $zong/$limit;
                $fenzuname = explode('/',$res['fenzuname']);
                $fenzuname = array_filter($fenzuname);
                $dqurl =  THTPADMIN;
                $token = request()->buildToken('__token__', 'sha1');
                return ['code'=>200,'message'=>'成功','data'=>array("diyi"=>$diyi,"dier"=>$dier,"disan"=>$disan,"list"=>$list,'count_page' => ceil($count_page),'fenzuname' => $fenzuname,'fenzunamecount' => count($fenzuname)),'dqurl'=>$dqurl,'token'=>$token, 'limit' => $limit];
            }
        }else{
            $page = input('get.page');
            if($page==1){
                $page=0;
            }else{
                $page=$page - 1;
            }
            $arrid = Cache::get('tpgettpoptionrankingbypid:'.'youfenzu'.$group.$pid.$page);
            if($arrid==""){
                $where = [];
                $limit = input('get.limit');
                $where[] = ["biaoid", "like",  $pid ];
                $where[] = ["group", "like",  $group ];
                $where[] = ["shenhe", "like",  0 ];
                $diyi = self::order('numpiao','desc')->field('id,name,image,outurl,numpiao')->where($where)->limit(0,1)->select();
                $dier = self::order('numpiao','desc')->field('id,name,image,outurl,numpiao')->where($where)->limit(1,1)->select();
                $disan = self::order('numpiao','desc')->field('id,name,image,outurl,numpiao')->where($where)->limit(2,1)->select();
                Cache::set('tpgettpoptionrankingbypid:'.'youfenzu'.$group.$pid.'yi',$diyi,310);
                Cache::set('tpgettpoptionrankingbypid:'.'youfenzu'.$group.$pid.'er',$dier,310);
                Cache::set('tpgettpoptionrankingbypid:'.'youfenzu'.$group.$pid.'san',$disan,310);
                $start=$page * $limit;
                if(isset($diyi[0]['id'])){
                    $where1[] = ["id", "<>",  $diyi[0]['id'] ];
                }
                if(isset($dier[0]['id'])){
                    $where1[] = ["id", "<>",  $dier[0]['id'] ];
                }
                if(isset($disan[0]['id'])){
                    $where1[] = ["id", "<>",  $disan[0]['id'] ];
                }
                if(isset($diyi[0]['id']) && isset($dier[0]['id']) && isset($disan[0]['id'])){
    
                }else{
                    $where1[] = ["id", "<>",  0 ];
                }
                $list = self::order('numpiao','desc')->field('id,name,image,outurl,numpiao')->where($where)->where($where1)->limit(intval($start),intval($limit))->select();
                Cache::set('tpgettpoptionrankingbypid:'.'youfenzu'.$group.$pid.$page,$list,310);
                $listcount = self::order('numpiao','desc')->field('id,name,image,outurl,numpiao')->where($where)->where($where1)->select();
                Cache::set('tpgettpoptionrankingbypid:'.'youfenzu'.$group.$pid.'zong',$listcount,310);
                $zong = count($listcount);
                $count_page = $zong/$limit;
                $fenzuname = explode('/',$res['fenzuname']);
                $fenzuname = array_filter($fenzuname);
                $dqurl =  THTPADMIN;
                $token = request()->buildToken('__token__', 'sha1');
                return ['code'=>200,'message'=>'成功','data'=>array("diyi"=>$diyi,"dier"=>$dier,"disan"=>$disan,"list"=>$list,'count_page' => ceil($count_page),'fenzuname' => $fenzuname,'fenzunamecount' => count($fenzuname)),'dqurl'=>$dqurl,'token'=>$token, 'limit' => $limit];
            }else{
                $limit = input('get.limit');
                $diyi = Cache::get('tpgettpoptionrankingbypid:'.'youfenzu'.$group.$pid.'yi');
                $dier = Cache::get('tpgettpoptionrankingbypid:'.'youfenzu'.$group.$pid.'er');
                $disan = Cache::get('tpgettpoptionrankingbypid:'.'youfenzu'.$group.$pid.'san');
                
                $list = Cache::get('tpgettpoptionrankingbypid:'.'youfenzu'.$group.$pid.$page);
                $listcount = Cache::get('tpgettpoptionrankingbypid:'.'youfenzu'.$group.$pid.'zong');
                $zong = count($listcount);
                $count_page = $zong/$limit;
                $fenzuname = explode('/',$res['fenzuname']);
                $fenzuname = array_filter($fenzuname);
                $dqurl =  THTPADMIN;
                $token = request()->buildToken('__token__', 'sha1');
                return ['code'=>200,'message'=>'成功','data'=>array("diyi"=>$diyi,"dier"=>$dier,"disan"=>$disan,"list"=>$list,'count_page' => ceil($count_page),'fenzuname' => $fenzuname,'fenzunamecount' => count($fenzuname)),'dqurl'=>$dqurl,'token'=>$token, 'limit' => $limit];
            }
        }
    }
}
